// Created from GroupGenerationTemplate
// For Decisions HL7 Engine
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using DecisionsFramework.Design.Properties;
using Decisions.HL7.DataTypes;
using ST = System.String;
using SI = System.String;
using IS = System.String;
using ID = System.String;
using SNM = System.String;

namespace Decisions.HL7.Message
{
    [DataContract]
	public class CLINICAL_HISTORY_DETAIL_CQU_I19 : AbstractGroup
    {
        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("46 OBR",46)]
  	    [HL7Field(HL7Version.v27, 46, HL7Repeat.False, HL7Required.True,"OBR")]
	    public OBR OBR {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("48 ODS",48)]
  	    [HL7Field(HL7Version.v27, 48, HL7Repeat.False, HL7Required.True,"ODS")]
	    public ODS ODS {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("50 PR1",50)]
  	    [HL7Field(HL7Version.v27, 50, HL7Repeat.False, HL7Required.True,"PR1")]
	    public PR1 PR1 {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("52 RF1",52)]
  	    [HL7Field(HL7Version.v27, 52, HL7Repeat.False, HL7Required.True,"RF1")]
	    public RF1 RF1 {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("54 AL1",54)]
  	    [HL7Field(HL7Version.v27, 54, HL7Repeat.False, HL7Required.True,"AL1")]
	    public AL1 AL1 {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("56 IAM",56)]
  	    [HL7Field(HL7Version.v27, 56, HL7Repeat.False, HL7Required.True,"IAM")]
	    public IAM IAM {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("58 ACC",58)]
  	    [HL7Field(HL7Version.v27, 58, HL7Repeat.False, HL7Required.True,"ACC")]
	    public ACC ACC {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("60 RMI",60)]
  	    [HL7Field(HL7Version.v27, 60, HL7Repeat.False, HL7Required.True,"RMI")]
	    public RMI RMI {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("62 DB1",62)]
  	    [HL7Field(HL7Version.v27, 62, HL7Repeat.False, HL7Required.True,"DB1")]
	    public DB1 DB1 {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("64 DG1",64)]
  	    [HL7Field(HL7Version.v27, 64, HL7Repeat.False, HL7Required.True,"DG1")]
	    public DG1 DG1 {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("66 DRG",66)]
  	    [HL7Field(HL7Version.v27, 66, HL7Repeat.False, HL7Required.True,"DRG")]
	    public DRG DRG {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("68 PDA",68)]
  	    [HL7Field(HL7Version.v27, 68, HL7Repeat.False, HL7Required.True,"PDA")]
	    public PDA PDA {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("71 OBX",71)]
  	    [HL7Field(HL7Version.v27, 71, HL7Repeat.True, HL7Required.False,"OBX")]
	    public OBX[] OBX {get;set;}



		#region Parser Helpers and Conrete Impls

        internal override void ConsumeTextSegmentsForGroup(Stack<string> availableData, HL7ParserOptions options) {

			OBR = PopSegmentParseAndCheckRequired<OBR>(availableData, options, "OBR");
			ODS = PopSegmentParseAndCheckRequired<ODS>(availableData, options, "ODS");
			PR1 = PopSegmentParseAndCheckRequired<PR1>(availableData, options, "PR1");
			RF1 = PopSegmentParseAndCheckRequired<RF1>(availableData, options, "RF1");
			AL1 = PopSegmentParseAndCheckRequired<AL1>(availableData, options, "AL1");
			IAM = PopSegmentParseAndCheckRequired<IAM>(availableData, options, "IAM");
			ACC = PopSegmentParseAndCheckRequired<ACC>(availableData, options, "ACC");
			RMI = PopSegmentParseAndCheckRequired<RMI>(availableData, options, "RMI");
			DB1 = PopSegmentParseAndCheckRequired<DB1>(availableData, options, "DB1");
			DG1 = PopSegmentParseAndCheckRequired<DG1>(availableData, options, "DG1");
			DRG = PopSegmentParseAndCheckRequired<DRG>(availableData, options, "DRG");
			PDA = PopSegmentParseAndCheckRequired<PDA>(availableData, options, "PDA");
			OBX = PopSegmentParseAndCheckRequiredArray<OBX>(availableData, options, "OBX");
        }

		internal override bool CanConsume(string availableData, HL7ParserOptions options)
        {
			bool isOBR = availableData.StartsWith("OBR", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("OBR", options.Version) || isOBR) {
				return isOBR;
			}
			bool isODS = availableData.StartsWith("ODS", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("ODS", options.Version) || isODS) {
				return isODS;
			}
			bool isPR1 = availableData.StartsWith("PR1", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("PR1", options.Version) || isPR1) {
				return isPR1;
			}
			bool isRF1 = availableData.StartsWith("RF1", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("RF1", options.Version) || isRF1) {
				return isRF1;
			}
			bool isAL1 = availableData.StartsWith("AL1", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("AL1", options.Version) || isAL1) {
				return isAL1;
			}
			bool isIAM = availableData.StartsWith("IAM", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("IAM", options.Version) || isIAM) {
				return isIAM;
			}
			bool isACC = availableData.StartsWith("ACC", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("ACC", options.Version) || isACC) {
				return isACC;
			}
			bool isRMI = availableData.StartsWith("RMI", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("RMI", options.Version) || isRMI) {
				return isRMI;
			}
			bool isDB1 = availableData.StartsWith("DB1", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("DB1", options.Version) || isDB1) {
				return isDB1;
			}
			bool isDG1 = availableData.StartsWith("DG1", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("DG1", options.Version) || isDG1) {
				return isDG1;
			}
			bool isDRG = availableData.StartsWith("DRG", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("DRG", options.Version) || isDRG) {
				return isDRG;
			}
			bool isPDA = availableData.StartsWith("PDA", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("PDA", options.Version) || isPDA) {
				return isPDA;
			}
			bool isOBX = availableData.StartsWith("OBX", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("OBX", options.Version) || isOBX) {
				return isOBX;
			}
			return false;
        }

        private static Dictionary<string, bool> SEGMENT_VERSION_REQUIRED_MAP = new Dictionary<string, bool>();

		protected override Dictionary<string, bool> MAP_OF_SEGMENT_TO_REQUIRED
        {
            get
			{
				return SEGMENT_VERSION_REQUIRED_MAP;
			}
        }

		public override string HL7ENTITY_TYPE_NAME
        {
            get {
				return "CLINICAL_HISTORY_DETAIL";
			}
        }

        static CLINICAL_HISTORY_DETAIL_CQU_I19() {

             SetupStaticPropertyMap(SEGMENT_VERSION_REQUIRED_MAP, typeof(CLINICAL_HISTORY_DETAIL_CQU_I19));

        }

		#endregion

		public override string GetER7(HL7ParserOptions options)
		{
			List<string> segmentData = new List<string>();
		 if (OBR != null) {
			string segmentValue = OBR.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (ODS != null) {
			string segmentValue = ODS.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (PR1 != null) {
			string segmentValue = PR1.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (RF1 != null) {
			string segmentValue = RF1.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (AL1 != null) {
			string segmentValue = AL1.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (IAM != null) {
			string segmentValue = IAM.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (ACC != null) {
			string segmentValue = ACC.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (RMI != null) {
			string segmentValue = RMI.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (DB1 != null) {
			string segmentValue = DB1.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (DG1 != null) {
			string segmentValue = DG1.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (DRG != null) {
			string segmentValue = DRG.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (PDA != null) {
			string segmentValue = PDA.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (OBX != null && OBX.Length > 0) {
			for (int i = 0; i < OBX.Length; i++) {
				string segmentValue = OBX[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
           return string.Join(HL7ParserConstants.SEGMENT_SEPARATOR, segmentData.ToArray());
        
        }
    }
}

